package org.example.evaluate.enums;

import java.math.BigDecimal;
import java.util.stream.Stream;

public enum GuaranteePeriod {
    one_month_more(12, "保修一个月以上", BigDecimal.valueOf(0.8)),
    less_one_month(13, "保修一个月内或过保", BigDecimal.valueOf(0.6));
    GuaranteePeriod(Integer code, String name, BigDecimal kf) {
        this.code = code;
        this.name = name;
        this.kf = kf;
    }

    private final Integer code;
    private final String name;
    private final BigDecimal kf;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public BigDecimal getKf() {
        return kf;
    }

    public static GuaranteePeriod buildGuaranteePeriod(Integer code) {
        return Stream.of(GuaranteePeriod.values())
                .filter(v -> v.getCode() == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException(String.format("传入的保修期状态码 [%s] 不正确", code)));
    }
}
